<?php
/**
 * 作者：亿泽
 * QQ：1260435972
 * 交流群：557649112
 * 日期：2022/03/31
 * 项目名称：亿泽不用验证系统
 * 项目说明：请勿进行违法用途，当您在使用本项目中的任何源代码时默认同意作者的观点！
 * 观点：
 * 1.禁止将本系统使用于违法违规用途。
 * 2.禁止将本系统使用包含但不限于 灰色产业/进行灰色产业的机器人插件/框架。
 * 3.禁止进行商业性质的二创二开，仅授权免费个人使用
 * 4.本系统为免费/全开源项目，禁止进行任何商业活动 除非 获得作者授权！
 * 感谢：
 * 1.使用了 光年 后台模板
 * 2.参考了 网络上部分代码资料
 * 3.感谢各位的使用~
 **/
function daddslashes ($string , $force = 0 , $strip = FALSE)
{
    !defined ('MAGIC_QUOTES_GPC') && define ('MAGIC_QUOTES_GPC' , get_magic_quotes_gpc ());
    if (!MAGIC_QUOTES_GPC || $force) {
        if (is_array ($string)) {
            foreach ($string as $key => $val) {
                $string[$key] = daddslashes ($val , $force , $strip);
            }
        } else {
            $string = addslashes ($strip ? stripslashes ($string) : $string);
        }
    }
    return $string;
}

function authcode ($string , $operation = 'DECODE' , $key = '' , $expiry = 0)
{
    $ckey_length = 4;
    $key = md5 ($key ? $key : ENCRYPT_KEY);
    $keya = md5 (substr ($key , 0 , 16));
    $keyb = md5 (substr ($key , 16 , 16));
    $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ($string , 0 , $ckey_length) : substr (md5 (microtime ()) , -$ckey_length)) : '';
    $cryptkey = $keya . md5 ($keya . $keyc);
    $key_length = strlen ($cryptkey);
    $string = $operation == 'DECODE' ? base64_decode (substr ($string , $ckey_length)) : sprintf ('%010d' , $expiry ? $expiry + time () : 0) . substr (md5 ($string . $keyb) , 0 , 16) . $string;
    $string_length = strlen ($string);
    $result = '';
    $box = range (0 , 255);
    $rndkey = array ();
    for ($i = 0; $i <= 255; $i++) {
        $rndkey[$i] = ord ($cryptkey[$i % $key_length]);
    }
    for ($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    }
    for ($a = $j = $i = 0; $i < $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $result .= chr (ord ($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
    }
    if ($operation == 'DECODE') {
        if ((substr ($result , 0 , 10) == 0 || substr ($result , 0 , 10) - time () > 0) && substr ($result , 10 , 16) == substr (md5 (substr ($result , 26) . $keyb) , 0 , 16)) {
            return substr ($result , 26);
        } else {
            return '';
        }
    } else {
        return $keyc . str_replace ('=' , '' , base64_encode ($result));
    }
}

function hj ()
{
    $hjmsg = 'TlhCNWN6VTJhVXcxWW5GUU5UVlRlRFpaVnpRMVlWY3lOV0o1UVRWWksxSTNOM2xOTlRaaFFqVnhNbWsxTlZOdk5VeHhUelZhVjBjMVRHbGhOVFZUYnpaWlExVTBORU5EVlZaSWRuWktiM3BPUkdkM1RtcHJNVTFVUVdkUFZGVXdUMFJCZDA5RVFYYz0=';
    return base64_decode (base64_decode (base64_decode ($hjmsg)));
}

function random ($length , $numeric = 0)
{
    $seed = base_convert (md5 (microtime () . $_SERVER['DOCUMENT_ROOT']) , 16 , $numeric ? 10 : 35);
    $seed = $numeric ? (str_replace ('0' , '' , $seed) . '012340567890') : ($seed . 'zZ' . strtoupper ($seed));
    $hash = '';
    $max = strlen ($seed) - 1;
    for ($i = 0; $i < $length; $i++) {
        $hash .= $seed[mt_rand (0 , $max)];
    }
    return $hash;
}

function selectconfig ($k)
{
    $config = Db ::table ("config") -> find ("*" , "k='$k' limit 1") -> fetch ();
    $v = $config['v'];
    return $v;
}

function saveconfig ($k , $v)
{
    global $row;
    $row = Db ::table ("config") -> rawexec ("UPDATE yz_config SET v ='$v' where k='$k'");

    if ($row != "0") {
        return true;
    } else {
        return false;
    }
}
/**
 *弹窗
 * msg = 展示内容
 * $type = 1 为信息 2为 成功 3为 提示 4 为错误
 *$ret 返回方式 1=返回上一级
 * 注：当$ret=0（只要是跳转到指定页面）时 需要输入 $retmsg 参数（指定跳转页面）；
 **/
function popup ($msg = '' , $type = 1 ,$ret = 1,$retmsg = "")
{
    switch ($type) {
        case 1:
            $panel = "信息";
            $color = "black";
            $btnClass = 'btn-black';
            break;
        case 2:
            $panel = "成功";
            $color = "green";
            $btnClass = 'btn-green';
            break;
        case 3:
            $panel = "提示";
            $color = "yellow";
            $btnClass = 'btn-yellow';
            break;
        case 4:
            $panel = "错误";
            $color = "red";
            $btnClass = 'btn-red';
            break;
    }
    switch ($ret) {
        case 0:
            $jsway="window.location.href='$retmsg'";
            break;
        case 1:
            $jsway="window.history.back(-1)";
            break;
    }
    echo "<script>
   $.confirm({
    title: '$panel',
    content: '$msg',
    type: '$color',
    typeAnimated: true,
    buttons: {
            somethingElse: {
            text: '知道了',
            btnClass: '$btnClass',
            keys: ['enter'],
            action: function(){
                $jsway
            }
        }
    }
});
    </script>";
}

/**
 *app状态
 * 1 为正常 2为 维护 0为 禁用
 **/
function app_state_op ($type = 0)
{
    switch ($type) {
        case 0:
            $panel = "禁用";
            $class = "badge badge-danger";
            break;
        case 1:
            $panel = "正常";
            $class = "badge badge-success";
            break;
        case 2:
            $panel = "维护";
            $class = "badge badge--warning";
            break;
        case 10:
            $panel = "免费";
            $class = "badge badge-success-light";
            break;
        case 11:
            $panel = "收费";
            $class = "badge badge-warning-light";
            break;
    }
    return "<span class=\"$class\">$panel</span>";
}
/**
 *app版本名称
 * $type 版本名称 0预览版 1内测版 2公测版 3最终测试版 4稳定版 5发行版 6零售版
 * $lang 语言选择 0中文版 1英文版
 **/
function appver_name_op ($type = 0,$lang=0)
{
if($lang == 0){
    switch ($type) {
        case 0:
            $panel = "预览版";
            break;
        case 1:
            $panel = "内测版";
            break;
        case 2:
            $panel = "公测版";
            break;
        case 3:
            $panel = "RC版";
            break;
        case 4:
            $panel = "稳定版";
            break;
        case 5:
            $panel = "发行版";
            break;
        case 6:
            $panel = "零售版";
            break;
    }
}else{
        switch ($type) {
            case 0:
                $panel = "Pre-alpha";
                break;
            case 1:
                $panel = "Alpha";
                break;
            case 2:
                $panel = "Beta";
                break;
            case 3:
                $panel = "Gamma";
                break;
            case 4:
                $panel = "Stable";
                break;
            case 5:
                $panel = "Release";
                break;
            case 6:
                $panel="Retail";
                break;
        }
}
    $class = "badge badge-warning-light";

    return "<span class=\"$class\">$panel</span>";
}
/**
 *app版本收费模式
 * 0为 免费 1为 收费
 **/
function appver_mod_op ($type = 0)
{
    switch ($type) {
        case 0:
            $panel = "免费";
            $class = "badge badge-success-light";
            break;
        case 1:
            $panel = "收费";
            $class = "badge badge-warning-light";
            break;
    }
    return "<span class=\"$class\">$panel</span>";
}
/**
 *app版本身份验证模式
 * 0为 无需验证 1为 登录验证 2为 卡密验证
 **/
function appver_auth_op ($type = 0)
{
    switch ($type) {
        case 0:
            $panel = "免验";
            $class = "badge badge-warning-light";
            break;
        case 1:
            $panel = "登录";
            $class = "badge badge-success-light";
            break;
        case 2:
            $panel = "卡密";
            $class = "badge badge-warning-light";
            break;
    }
    return "<span class=\"$class\">$panel</span>";
}
/**
 *app版本 状态查看;
 * $type 选择颜色 0红 1绿 2蓝 3蔚蓝 4橘黄 5黑色 6灰色 7紫 8粉 9青 10黄 11棕 12白色 13柔黑;
 * $msg 徽章 内容;
 * $state 模式 默认 0无模式 1颜色减淡 2椭圆形 3边框圆点 10椭圆+减淡 11圆点+减淡 12椭圆+圆点;
 **/
function badge_op ($type = 1 ,$msg='',$state=0)
{
    switch ($state) {
        case 0:
            break;
        case 1:
            //颜色减淡
            $s1 = "-light";
            break;
        case 2:
            //椭圆形
            $s2 = " badge-pill ";
            break;
        case 3:
            //边框带圆点
            $s3 = "-outline";
            break;
        case 10:
            $s1 = "-light";
            $s2 = " badge-pill ";
            break;
        case 11:
            $s1 = "-light";
            $s3 = "-outline";
            break;
        case 12:
            $s2 = " badge-pill ";
            $s3 = "-outline";
            break;
    }
    switch ($type) {
        case 0:
            //红色
            $class = "badge $s2 badge$s3-danger$s1";
            break;
        case 1:
            //绿色
            $class = "badge $s2 badge$s3-success$s1";
            break;
        case 2:
            //蓝色
            $class = "badge $s2 badge$s3-primary$s1";
            break;
        case 3:
            //蔚蓝色
            $class = "badge $s2 badge$s3-info$s1";
            break;
        case 4:
            //橘黄色
            $class = "badge $s2 badge$s3-warning$s1";
            break;
        case 5:
            //黑色
            $class = "badge $s2 badge$s3-dark$s1";
            break;
        case 6:
            //灰色
            $class = "badge $s2 badge$s3-secondary$s1";
            break;
        case 7:
            //紫色
            $class = "badge $s2 badge$s3-purple$s1";
            break;
        case 8:
            //粉色
            $class = "badge $s2 badge$s3-pink$s1";
            break;
        case 9:
            //青色
            $class = "badge $s2 badge$s3-cyan$s1";
            break;
        case 10:
            //黄色
            $class = "badge $s2 badge$s3-yellow$s1";
            break;
        case 11:
            //棕色
            $class = "badge $s2 badge$s3-brown$s1";
            break;
        case 12:
            //白色
            $class = "badge $s2 badge$s3-light$s1";
            break;
        case 13:
            //柔黑
            $class = "badge $s2 badge$s3-muted$s1";
            break;
    }
    return "<span class=\"$class\">$msg</span>";
}
